local NoticeLayer = {}

NoticeLayer.m_PanelNotice = nil
 
function NoticeLayer.show( widget )
    print("============NoticeLayer.show===============")
    NoticeLayer:init( widget )
end

function NoticeLayer:closeWindow() 
    self.m_PanelNotice:setLocalZOrder(-1)
    self.m_PanelNotice:setVisible(false)
end


function NoticeLayer:init( widget )
    print("============NoticeLayer:init============")
    
    self.m_PanelNotice = ccui.Helper:seekWidgetByName(widget.m_Json,"PanelNotice")
    self.m_PanelNotice:setPositionX(0)
    self.m_PanelNotice:setPositionY(0) 
    self.m_PanelNotice:setVisible(true)
    self.m_PanelNotice:setLocalZOrder(5)
 
    self.m_BtnBack = ccui.Helper:seekWidgetByName(self.m_PanelNotice,"BtnBack")
    self.m_BtnBack:setTouchEnabled(true)
    self.m_BtnBack:addTouchEventListener(function(sender,eventType)self:onMenutClick(sender,eventType) end)
    
    self.m_BtnSound = ccui.Helper:seekWidgetByName(self.m_PanelNotice,"BtnSound")
    self.m_BtnSound:setTouchEnabled(true)
    self.m_BtnSound:addTouchEventListener(function(sender,eventType)self:onMenutClick(sender,eventType) end)
 
    self.m_ListViewNotice = ccui.Helper:seekWidgetByName(self.m_PanelNotice,"ListViewNotice")
 
    self.m_listView = ccui.ListView:create()
    self.m_listView:setDirection(ccui.ScrollViewDir.vertical)
    self.m_listView:setBounceEnabled(true)
--    self.m_listView:setBackGroundColor(cc.c3b(0,255,0))
--    self.m_listView:setBackGroundColorType(ccui.LayoutBackGroundColorType.solid)
    self.m_listView:setBackGroundImageScale9Enabled(true)
    self.m_listView:setContentSize(cc.size(480, 754))
    self.m_listView:setPosition(cc.p(0,0))
    self.m_listView:addEventListener(handler(self, self.listViewEvent))
    self.m_listView:addScrollViewEventListener(handler(self, self.scrollViewEvent))
    self.m_PanelNotice:addChild(self.m_listView) 
    
    local list =  ds.Launcher:getNoticeList() 
    for i = 1, #list do
  --    local item = require "view/Launcher/NoticeItem".create()
   --   self.m_listView:pushBackDefaultItem(item)
    end
  
end

function NoticeLayer:listViewEvent(sender, eventType)
    if eventType == ccui.ListViewEventType.ons_selected_item then
        print("select child index = ",sender:getCurSelectedIndex())
    end
end

function NoticeLayer:scrollViewEvent(sender, evenType)
    if evenType == ccui.ScrollviewEventType.scrollToBottom then
        print("SCROLL_TO_BOTTOM")
    elseif evenType ==  ccui.ScrollviewEventType.scrollToTop then
        print("SCROLL_TO_TOP")
    end
end

function NoticeLayer:onMenutClick(sender,eventType)
    if eventType == ccui.TouchEventType.ended then
        if sender == self.m_BtnSound then     
            print "=========NoticeLayer:onMenutClick m_BtnSound======================="
        elseif sender == self.m_BtnBack then     
            print "=========NoticeLayer:onMenutClick m_BtnBack======================="
            self:closeWindow()
        end
    end
end
 
return NoticeLayer